function mviewToastr(status, text, time = 3, close = true) {
    $(".m-toastr").stop();
    var showTime = time * 1000;
    var icon = "icon-chenggong";
    if (status == "success") {
        icon = "icon-chenggong";
    } else if (status == "info") {
        icon = "icon-wenda";
    } else if (status == "warning") {
        icon = "icon-tanhao";
    } else if (status == "error") {
        icon = "icon-shibai";
    } else if (status == "question") {
        icon = "icon-bangzhu";
    } else if (status == "load") {
        icon = "icon-loading1 m-spin"
    }
    if ($(".m-toastr").length <= 0) {
        $("body").prepend('<div class="m-toastr"></div>');
    }
    var html = '<div class="m-toastr-msg ' + status + '"><i class="icon iconfont ' + icon + '"></i><font>' + text + '</font>';
    if (close) { html += '<i class="close iconfont icon-guanbi" onclick="colsemviewToastr();"></i>' } html += '</div>';
    $(".m-toastr").stop();
    $(".m-toastr").hide();
    $(".m-toastr").html(html);
    $(".m-toastr").slideDown(300);
    $(".m-toastr").delay(showTime).slideUp(300)
}

function colsemviewToastr() { $(".m-toastr").stop() }

function mviewNotification(status, title = "确认是否操作", describe = "请确认是否完成操作？", confirmText = "确定", cancelText = "取消", data) {
    var icon = "icon-chenggong";
    if (status == "success") {
        icon = "icon-chenggong";
    } else if (status == "info") {
        icon = "icon-wenda";
    } else if (status == "warning") {
        icon = "icon-tanhao";
    } else if (status == "error") {
        icon = "icon-shibai";
    } else if (status == "question") {
        icon = "icon-bangzhu";
    } else if (status == "load") {
        icon = "icon-loading m-spin"
    }
    var html = '<div class="m-notification-cotainer"><div class="message ' + status + '"><div class="nheader"><i class="icon iconfont ' + icon + '"></i><font>' + title + '</font><i class="close iconfont icon-guanbi" onclick="colseMviewNotification();"></i></div><div class="nbody">' + describe + '</div><div class="nfooter"><ul><li onclick="confirmMviewNotification();">' + confirmText + '</li><li onclick="colseMviewNotification();">' + cancelText + '</li></ul></div></div><div class="m-notification-shadow"></div><input id="mviewNotificationData" type="hidden" value=\'' + JSON.stringify(data) + '\'></div>';
    $("body").append(html);
    $(".m-notification-cotainer").slideDown(300) }

function colseMviewNotification() { $(".m-notification-shadow").hide();
    $(".m-notification-cotainer").slideUp(300);
    setTimeout(function() { $(".m-notification-cotainer").remove() }, 300);
}

function mviewTopNotice(id,top,label,html,link,down_id,main_id) {
    var mviewTopNoticeStatus = localStorage.getItem("mview_top_notice_"+id) || 1;
    if (mviewTopNoticeStatus == 1) {
        var mviewTopNoticeHtml = '<div class="m-notice" id="'+id+'" style="margin-top: '+top+'px;"><div class="m-notice-left">';
        if (label != "") {
            mviewTopNoticeHtml += '<span>'+label+'</span>';
        }
        mviewTopNoticeHtml += '<font onclick="mviewTopNoticeRedirect(\''+link+'\')">'+html+' <i class="bx bx-chevrons-right"></i></font></div><i class="bx bx-x" onclick="mviewTopNoticeClose(\''+id+'\',\''+down_id+'\')"></i></div>';
        $(main_id).prepend(mviewTopNoticeHtml);
        $("#"+down_id).css({"margin-top":"-"+(top+5)+"px"});
    } else {
        return;
    }
}

function mviewTopNoticeRedirect(url) {
    window.open(url,"_blank");
}

function mviewTopNoticeClose(id,down_id) {
    localStorage.setItem("mview_top_notice_"+id,2);
    $("#"+id).remove();
    $("#"+down_id).attr("style","");
}

function mviewPicker(id,callback) {
    var html = '<li onclick="mviewPickerItem(this,\'\')" data="">全部</li>';
    var data = JSON.parse($("#sort_item").val());
    $("#sort_item").val();
    $.each(data,(i,m) => {
        html += '<li onclick="mviewPickerItem(this,\''+id+'\')" data="'+m.id+'">'+m.name+'</li>';
    });
    $("#"+id+" .m-picker-items ul").html(html);
    $("#"+id+" .m-picker-items").slideToggle();
    $("#"+id+" .m-picker-items input").focus();
    $("#"+id+"_search").val("");
}

function mviewPickerItem(obj,id) {
    var data = $(obj).attr("data");
    var value = $(obj).text();
    $("#"+id+"_value").val(data);
    $("#"+id+" .text span").text(value);
    $("#"+id+" .m-picker-items").hide();
}

function mviewPickerSearch(id,event) {
    var data = JSON.parse($("#sort_item").val());
    var searchText = event.target.value;
    var html = '';
    $.each(data,(i,m) => {
        if (m.name.indexOf(searchText) !== -1) {
            html += '<li onclick="mviewPickerItem(this,\''+id+'\')" data="'+m.id+'">'+m.name+'</li>';
        }
    });
    if (html == "") {
        $("#"+id+" .m-picker-items ul").html('<li>暂无记录</li>');
    } else {
        $("#"+id+" .m-picker-items ul").html(html);
    }
}

function mviewPickerClose(id) {
    setTimeout(function() {
        $("#"+id+" .m-picker-items").hide();
    },100);
}
